cmake_minimum_required(VERSION 3.5.1)
project(mbtilesCpp)

set(CMAKE_CXX_STANDARD 14)

set(SOURCE_FILES
        ${CMAKE_CURRENT_LIST_DIR}/Source/vector_tile21/vector_tile.pb.cc
        ${CMAKE_CURRENT_LIST_DIR}/Include/vector_tile21/vector_tile.pb.h
        ${CMAKE_CURRENT_LIST_DIR}/Source/MBTileReader.cpp
        ${CMAKE_CURRENT_LIST_DIR}/Include/MBTileReader.h
        ${CMAKE_CURRENT_LIST_DIR}/Source/VectorTile.cpp
        ${CMAKE_CURRENT_LIST_DIR}/Include/VectorTile.h
        ${CMAKE_CURRENT_LIST_DIR}/cppGzip/DecodeGzip.cpp
        ${CMAKE_CURRENT_LIST_DIR}/cppGzip/DecodeGzip.h
        ${CMAKE_CURRENT_LIST_DIR}/cppGzip/EncodeGzip.cpp
        ${CMAKE_CURRENT_LIST_DIR}/cppGzip/EncodeGzip.h
        ${CMAKE_CURRENT_LIST_DIR}/cppGzip/HandleDeflate.h)

#       Examples/example.cpp
#       Examples/example2.cpp

#pull in some helpers
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(FindProtobuf)
include(FindZLIB)

#find sqlite
find_package (SQLite3)

if(WIN32)
    find_library(icuuc icuuc "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/icu4c/lib")
else()
    find_library(icuuc icuuc /usr)
endif()

if(BUILD_SHARED_LIBS)
    add_library(mbtilesCpp SHARED ${SOURCE_FILES})
else()
    add_library(mbtilesCpp STATIC ${SOURCE_FILES})
endif()

target_include_directories(mbtilesCpp PUBLIC
    ${CMAKE_CURRENT_LIST_DIR}/Include/
    ${CMAKE_CURRENT_LIST_DIR}/thirdparty/icu4c/Include/
    ${SQLITE3_INCLUDE_DIR}
    ${Protobuf_INCLUDE_DIR}
    ${ZLIB_INCLUDE_DIR} )
TARGET_LINK_LIBRARIES(mbtilesCpp
    ${SQLITE3_LIBRARY}
    ${icuuc}
    ${PROTOBUF_LIBRARIES}
    ${ZLIB_LIBRARY} )

add_executable(example1 Examples/example.cpp)
TARGET_LINK_LIBRARIES(example1
    mbtilesCpp
    ${SQLITE3_LIBRARY}
    ${PROTOBUF_LIBRARIES}
    ${ZLIB_LIBRARY} )

add_executable(example2 Examples/example2.cpp)
TARGET_LINK_LIBRARIES(example2
    mbtilesCpp
    ${SQLITE3_LIBRARY}
    ${PROTOBUF_LIBRARIES}
    ${ZLIB_LIBRARY} )

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Examples/tampbf.mbtiles DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
if(WIN32)
   file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/icu4c/bin/icudt71.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
   file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/icu4c/bin/icuuc71.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()